﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GEMINI_OP10
{
    public partial class FormSeting : Form
    {
        public FormSeting()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(textBox2.Text);
            sb.AppendLine(textBox3.Text);
            sb.AppendLine(textBox4.Text);
            sb.AppendLine(textBox5.Text);
            sb.AppendLine(textBox9.Text);
            sb.AppendLine(textBox8.Text);
            //螺钉数1
            sb.AppendLine(textBox6.Text);
            //螺钉数2
            sb.AppendLine(textBox7.Text);
            File.WriteAllText(Application.StartupPath + "\\" + "型号" + "\\" + textBox1.Text + ".txt", sb.ToString());
            //FormMain.PLC_Link[0].WriteByte("DB99.DBB1", Convert.ToByte(textBox6.Text));     //螺钉枪1数量
            //FormMain.PLC_Link[0].WriteByte("DB99.DBB2", Convert.ToByte(textBox7.Text));     //螺钉枪2数量
        }

        private void FormSeting_Load(object sender, EventArgs e)
        {
            var fils = Directory.GetFiles(Application.StartupPath + "\\" + "型号", "*.txt");
            for (int i = 0; i < fils.Length; i++)
            {
                comboBox1.Items.Add(fils[i].Substring(fils[i].LastIndexOf("\\") + 1, fils[i].Length - 4 - (fils[i].LastIndexOf("\\") + 1)));
            }
        }
        string[] readSeting = new string[5];
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            readSeting = File.ReadAllLines(Application.StartupPath + "\\" + "型号" + "\\" + comboBox1.Text + ".txt");
            textBox1.Text = comboBox1.Text;
            textBox2.Text = readSeting[0];
            textBox3.Text = readSeting[1];
            textBox4.Text = readSeting[2];
            textBox5.Text = readSeting[3];
            textBox9.Text = readSeting[4];
            textBox8.Text = readSeting[5];
            //螺钉1
            textBox6.Text = readSeting[6];
            //textBox6.Text = FormMain.PLC_Link[0].ReadByte(S7.Net.DataType.DataBlock, 99, 1).ToString();
            //螺钉2
            textBox7.Text = readSeting[7];
            //textBox7.Text = FormMain.PLC_Link[0].ReadByte(S7.Net.DataType.DataBlock, 99, 2).ToString();
        }
    }
}
